/*
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *
 *  Authors:
 *  	Albert Marieges Garcia
 *  	Álex Pardo Fernández
 *  	Enric Mayas Márquez
 *  	Juan Carlos Calvo Tejedor
 *  	Marc Gironés Dezsényi
 *  
 *  Contact:
 *  	bcn.tours.android@gmail.com
 *  Webpage:
 *  	bcntours.co.cc
 *
 */
package com.BCNTours.Vista;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

import com.BCNTours.R;

/**
 * Works toguether with Search.java in order to perform string searches between all of the POIs and display the results.
 *
 */
public class SearchListItemView extends TextView{
	/*Attributions*/
	private Paint marginPaint;
	private Paint linePaint;
	private int paperColor;
	private float margin;
		
	/**
	 * Constructor of the class
	 * @param context
	 * @param ats
	 * @param ds
	 */
	public SearchListItemView (Context context, AttributeSet ats, int ds) {
		super(context, ats, ds);
		init();
	}
	
	/**
	 * Constructor of the class
	 * @param context
	 * @param ats
	 * @param ds
	 */
	public SearchListItemView (Context context) {
		super(context);
		init();
	}

	/**
	 * Constructor of the class
	 * @param context
	 * @param ats
	 * @param ds
	 */
	public SearchListItemView (Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	private void init() {
		// Get a reference to our resource table.
		Resources myResources = getResources();
		
		// Create the paint brushes we will use in the onDraw method.
		marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		marginPaint.setColor(myResources.getColor(R.color.notepad_margin));
		linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		linePaint.setColor(myResources.getColor(R.color.notepad_lines));
		
		// Get the paper background color and the margin width.
		paperColor = myResources.getColor(R.color.notepad_paper);
		margin = myResources.getDimension(R.dimen.notepad_margin);
	}

	@Override
	public void onDraw(Canvas canvas) {
		 // Color as paper
		canvas.drawColor(paperColor);
		
		// Draw ruled lines
		canvas.drawLine(0, 0, getMeasuredHeight(), 0, linePaint);
		canvas.drawLine(0, getMeasuredHeight(), 
		                   getMeasuredWidth(), getMeasuredHeight(), 
		                   linePaint);
		
		// Draw margin
		canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint);
		
		// Move the text across from the margin
		canvas.save();
		canvas.translate(margin, 0);
		
		// Use the TextView to render the text.
		super.onDraw(canvas);
		canvas.restore();
	}
}